package com.example.demo.controller;

import com.example.demo.model.BlogInfo;
import com.example.demo.service.BlogInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/blog")
public class BlogInfoController {
    @Autowired
    private BlogInfoService blogInfoService;
    /*
    获取博客列表
     */
    @RequestMapping("/getList")
    public List<BlogInfo> getList(){
        log.info("获取博客列表");
        List<BlogInfo> list=blogInfoService.select();
        return list;
    }
    @RequestMapping("/getBlogById")
    public BlogInfo getBlogById(Integer id){
        BlogInfo blogInfo = blogInfoService.selectById(id);
        return blogInfo;
    }

    @RequestMapping("/deleteById")
    public Integer deleteById(Integer id){
        Integer result=blogInfoService.delete(id);
        return result;
    }

    @RequestMapping("/updateBlog")
    public Integer updateBlog(BlogInfo blogInfo){
        Integer result=blogInfoService.update(blogInfo);
        return result;
    }

    @RequestMapping("/insertBlog")
    public Integer insertBlog(BlogInfo blogInfo){
        Integer result=blogInfoService.insert(blogInfo);
        return result;
    }

    public BlogInfo getBlogDetail(Integer blogId){
        return blogInfoService.getBlogDetail(blogId);
    }

}
